package com.css.apps.base.user.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.css.apps.base.user.model.SUser;
import com.css.db.query.QueryCache;
import com.css.webbase.webwork.action.AdminAction;

@SuppressWarnings("serial")
public class DirUserCountGraphPie extends AdminAction {

	/*
	 * 按照用户状态（使用中、注销、停用）展示用户数的统计表格，统计饼图 表格导出 以集团和二级企业为维度统计用户状态及总数的数量表格
	 * 以集团和二级企业为维度统计用户状态的数量柱状图
	 */
	// private String companyLevel = "1";// 1 中国电子 2 下级企业
	private String usrStatus = "1"; // 1 使用中 2 注销 3 停用
	private Date startTime;
	private List<String> tabHeader = new ArrayList<>();
	private List<Object[]> tabData = new ArrayList<>();
	private StringBuffer values;

	@Override
	protected String adminGo() {
		setTabHeader();
		setTabData();
		return SUCCESS;
	}

	@SuppressWarnings("unchecked")
	private void setTabData() {
		tabData.clear();
		List<SUser> res = new QueryCache("from SUser u where u.delFlag = '2' and u.openFlag = :openFlag ")
				.setParameter("openFlag", usrStatus).list();
		int cec = 0;
		int company = 0;
		// TODO 无IDS时, 如何区分总部与直属单位用户?
		for (@SuppressWarnings("unused") SUser sUser : res) {
			/*if (sUser.getUserLevel() != null && sUser.getUserLevel().equals("2")) {
				company++;
			} else {
				cec++;
			}*/
		}
		values = new StringBuffer();
		Object[] row = new Object[2];
		Object[] row1 = new Object[2];
		row[0] = "中国电子";
		row[1] = cec; // 使用当前状态的人数
		tabData.add(row);
		row1[0] = "下级企业";
		row1[1] = company; // 使用当前状态的人数
		tabData.add(row1);
		values.append("{value:" + row[1] + ",name:'" + row[0] + "'}");
		values.append("," + "{value:" + row1[1] + ",name:'" + row1[0] + "'}");
	}

	private void setTabHeader() {
		tabHeader.clear();
		tabHeader.add("企业等级");
		tabHeader.add("人数");
		// tabHeader.add("占总人数比重");
	}

	/*
	 * public String getUsrStatus() { return usrStatus; }
	 * 
	 * public void setUsrStatus(String usrStatus) { this.usrStatus = usrStatus;
	 * }
	 */

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public List<String> getTabHeader() {
		return tabHeader;
	}

	public void setTabHeader(List<String> tabHeader) {
		this.tabHeader = tabHeader;
	}

	public List<Object[]> getTabData() {
		return tabData;
	}

	public void setTabData(List<Object[]> tabData) {
		this.tabData = tabData;
	}

	public StringBuffer getValues() {
		return values;
	}

	public void setValues(StringBuffer values) {
		this.values = values;
	}

	public String getUsrStatus() {
		return usrStatus;
	}

	public void setUsrStatus(String usrStatus) {
		this.usrStatus = usrStatus;
	}

}
